/*
 * $Id: GzippedRequestDataSet.java,v 1.2 2009/07/10 17:59:22 navdeep_mahajan Exp $
 * 
 * Copyright (C) 2008 General Electric Company. All Rights Reserved.
 * 
 * This software is the confidential and proprietary information of the General
 * Electric Company (GE). You shall not disclose this software and shall use it
 * only in accordance with the terms of the license agreement you entered into
 * with GE.
 * 
 * GE MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
 * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
 * NON-INFRINGEMENT. GE SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
 * AS A RESULT OF USING, MODIFYING, OR DISTRIBUTING THIS SOFTWARE OR ITS
 * DERIVATIVES.
 */
package com.ge.healthcare.autosc.common.requestData;

import java.io.File;
import java.io.InputStream;
import java.util.zip.GZIPInputStream;

import com.ge.healthcare.autosc.common.exceptions.BasicException;
import com.ge.healthcare.autosc.common.util.ZipperUtil;

/**
 * A request data set where the data set is a gzipped file. This allows allows a
 * data set to be opened.
 * 
 * @author 212042946
 * 
 */
public class GzippedRequestDataSet extends RequestDataSet {

	/**
	 * Construct a request data set where the source file is a gzipped file.
	 * 
	 * @param name
	 *            The name of the data set. This is the name used to refer to
	 *            the data set by objects messaging an AscRequestData object.
	 * 
	 * @param sourceFile
	 *            The file which is the source of this data set. When opening
	 *            this data set, this file will be opened. The stream returned
	 *            from opening this file may be filtered before being made
	 *            available to the requestor.
	 */
	public GzippedRequestDataSet(String name, File sourceFile) {
		super(name, sourceFile);
	}

	/**
	 * Open, for reading, the data set. The returned stream is buffered. It is
	 * the responsibility of the calling code to close the stream. No messages
	 * need be logged on success, the caller will log the success message. This
	 * is a helper for the openDataSet() method.
	 * 
	 * @param myHelper
	 *            Helper object for reporting errors.
	 * 
	 * @return Buffered input stream to use for reading the data set.
	 * 
	 * @exception AscServiceAbortException
	 *                If unable to open the data set.
	 */
	protected InputStream openStream() throws BasicException {
		GZIPInputStream gzipStream = ZipperUtil.openAsZip(getSourceFile());
		if (gzipStream == null) {
			throw new BasicException("Failed opening gzip file "
					+ getSourceFile().getPath());
		}
		return gzipStream;
	}

	/**
	 * Generate the message used to indicate that the data set was successfully
	 * opened for reading.
	 * 
	 * @return The message indicating the data set was successfully opened.
	 */
	protected String getSuccessMessage() {
		return getSourceFilePath() + " opened, with uncompression, for reading";
	}

	/**
	 * Retrieve the size, in bytes, of the data set.
	 * 
	 * @param myHelper
	 *            Helper object for reporting errors.
	 * 
	 * @return The size, in bytes, of the data set.
	 * 
	 * @exception AscServiceAbortException
	 *                If unable to determine the size of the data set.
	 */
	public long dataSetSize() throws BasicException {
		return 0;
	}
}
